/*
 * Utils.cpp
 *
 *  Created on: 2013. 9. 9.
 *      Author: mega@gamevil.com
 */

#include <random>
#include "Utils.h"
#include "../xldata/egg_grade.h"

namespace ProjectZ { namespace NUtil {

MarketType GetMarketType(int company, int saleCode)
{
	if (company == MARKET_GOOGLE)
	{
		switch (saleCode)
		{
		case SC_KAKAO_GOOGLE:
			return MarketType::AD_KAKAO;
		}
	}

	if (company == MARKET_IOS)
	{
		switch (saleCode)
		{
		case SC_KAKAO_IOS:
			return MarketType::IOS_KAKAO;
		}
	}

	return MarketType::__NONE__;
}

int GetRandBetween(int minVal, int maxVal)
{
	if (maxVal < minVal)
		maxVal = minVal;

	return (rand() % (maxVal - minVal + 1)) + minVal;
}

int AddPercentage(int value, int per)
{
	return value + (value * (per / 100.0) );
}

int GetEggGrade(int itemQuality)
{
	// 연출용 알 등급 결정
	int accRate = 0;
	int eggGrade = 0;
	int eggRate = rand() % 100;

	for ( ; eggGrade < NXLData::EGG_GRADE_EGG_GRADE_MAX; eggGrade++)
	{
		const NXLData::EGG_GRADE_EGG_GRADE * egg = &NXLData::stEgg_Grade_Egg_Grade[eggGrade];

		switch (itemQuality)
		{
		case 0: accRate += egg->star1_rate4; break;
		case 1: accRate += egg->star2_rate5; break;
		case 2: accRate += egg->star3_rate6; break;
		case 3: accRate += egg->star4_rate7; break;
		case 4: accRate += egg->star5_rate8; break;
		case 5: accRate += egg->star6_rate9; break;
		case 6: accRate += egg->star7_rate10; break;
		case 7: accRate += egg->star8_rate11; break;
		case 8: accRate += egg->star9_rate12; break;
		case 9: accRate += egg->star10_rate13; break;
		}

		if (eggRate < accRate)
		{
			break;
		}
	}

	if (eggGrade == NXLData::EGG_GRADE_EGG_GRADE_MAX)
	{
		eggGrade -= 1;
	}

	return eggGrade;
}

} /*NUtil*/ } /*ProjectZ*/



